package com.durian.base.utils;

import com.durian.base.frame.ActivityStack;

/**
 * 说明：BackTools
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-06-17 17:58
 * <p/>
 * 版本：version 1.0
 */
public class BackTools {
    private static long touchTime = 0;

    public static class BackExit {

        /**
         * 说明：退出提示
         */
        public void showTips() {
        }

        public void exit() {
            ActivityStack.create().AppExit();
        }

        public long setWaitTime() {
            return 2000;
        }
    }

    public static void onBackPressed(BackExit backExit){
        long waitTime = backExit.setWaitTime();
        if (waitTime <= 0){
            waitTime = 2000;
        }
        long currentTime = System.currentTimeMillis();
        if ((currentTime - touchTime) >= waitTime){
            backExit.showTips();
            touchTime = currentTime;
        }else {
            //退出
            backExit.exit();
        }
    }
}
